<?php  

namespace App\Services;
use App\Models\Smslists;
use Log;

class SmsService
{
    // 发送短信操作
    public static function messageClient($phone,$message,$status)
    {
        $content = iconv("utf-8","gb2312",$message);
        $ch = curl_init();
        //设置选项，包括URL
        curl_setopt($ch, CURLOPT_URL, "http://114.255.71.158:8061/?username=qushua&password=".md5("Mzd6688")."&message=".$content."&phone=".$phone."&epid=122042&linkid=&subcode=");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        //执行并获取HTML文档内容
        $output = curl_exec($ch);
        //释放curl句柄
        curl_close($ch);
        //打印获得的数据
        if($output=="00"){
            //短信发送成功了，把短信加入日志
            Smslists::insertRegisterSms($phone,$message,$status);
            return true;
        }
        Log::info($output);
        return false;
    }

    public static function sendRegMsn($phone = "",$code)
    {
        $message="【天天外链】验证码：".$code."，您正在登录天天外链，请勿将验证码告诉他人！";
        $sendstatus = self::messageClient($phone,$message,1);
        if ($sendstatus) return true;
        return false;
    }

    public static function memberMotice($phone,$date)
    {
        $message="【天天外链】您的会员即将在".$date."过期，请及时前往天天外链后台续费。已续费请忽略！";
        $sendstatus = self::messageClient($phone,$message,1);
        if ($sendstatus) return true;
        return false;
    }
}